﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CDefineGlobal;
using System.Drawing;

namespace CObject
{
    public abstract class CChiHuyState
    {
        public CChiHuy ChiHuy { set; get; }

        public abstract void Die();
        public abstract void Revive();
    }

    class AliveState : CChiHuyState
    {
        public AliveState(CChiHuy c)
        {
            this.ChiHuy = c;
            this.ChiHuy.Picture = new Bitmap("Pictures\\ChiHuy.bmp");
        }

        public override void Die()
        {
            this.ChiHuy.IsAlive = false;
            CheckSwitchState();
        }

        public override void Revive()
        {
            return;
        }

        public void CheckSwitchState()
        {
            this.ChiHuy.State = new DeadState(this.ChiHuy);
        }
    }

    class DeadState : CChiHuyState
    {
        public DeadState(CChiHuy c)
        {
            this.ChiHuy = c;
            this.ChiHuy.Picture = new Bitmap("Pictures\\ChiHuy2.bmp");
        }

        public override void Revive()
        {
            this.ChiHuy.IsAlive = true;
            CheckSwitchState();
        }

        public override void Die()
        {
            return;
        }

        public void CheckSwitchState()
        {
            this.ChiHuy.State = new AliveState(this.ChiHuy);
        }
    }

    public class CChiHuy : AbstractTile
    {
        //bức ảnh chỉ huy bị nổ
        public CChiHuyState State {get; set;}
        public Boolean IsAlive { get; set; }

         //constructor
        public CChiHuy()
        {
            this.Init();
        }

        override public void Init()
        {
            this.I_Type = CDefine.TILE_CHI_HUY;
            this.I_Property = -1;   //chưa xử lí

            this.State = new AliveState(this);
        }

        public void Die()
        {
            this.State.Die();
        }

        public void Revive()
        {
            this.State.Revive();
        }
    }

}
